package com.dsl.dslallinone.dto;

/**
 * 时间粒度枚举
 */
public enum Granularity {
    HOUR("hour", "小时"),
    DAY("day", "日"),
    MONTH("month", "月");

    private final String code;
    private final String desc;

    Granularity(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static Granularity fromCode(String code) {
        for (Granularity granularity : values()) {
            if (granularity.code.equals(code)) {
                return granularity;
            }
        }
        throw new IllegalArgumentException("Unknown granularity code: " + code);
    }
}
